/**
 * Copyright (c) 2017 hadlinks, All Rights Reserved.
 */
package com.bugull.farm.core.proxy;

import com.alibaba.fastjson.JSONObject;
import com.bugull.farm.core.annotation.LogAnnotation;
import com.bugull.farm.core.utils.StringUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * Project Name: bugu-farm-household 
 * Package Name: com.bugull.farm.core.proxy 
 * ClassName: AfterHandler 
 * Function: TODO ADD FUNCTION.  
 * date: 2017/11/7 17:15
 * @author songwei (songw@hadlinks.com)
 * @since JDK 1.8 
 */
public abstract class AfterHandler extends AbstractHandler {

    public abstract void handleAfter(Object proxy, Method method, Object[] args);

    /* (non-Javadoc)
     * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        Object result = method.invoke(getTargetObject(), args);
        //过滤代理的方法，去除继承自Object的基础函数
        if (method.getName().startsWith("cal")) {
            handleAfter(proxy, method, args);
        }
        return result;
    }
}
